package com.useeinfo.oa.modules.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.enums.AuditTypeEnum;
import com.useeinfo.oa.modules.security.entity.SystemUser;

import javax.persistence.*;

/**
 * @Auther: xudong.sun
 * @Date: 2018/12/3 14:33
 * @Description: 审批流线路表
 */
@Entity
@Table(name = "audit_flow")
public class AuditFlow extends SuperClassEntity<AuditFlow> {
    /**
     * 审批流名称
     */
    private String flowName;
    /**
     * 所属应用
     */
    @ManyToOne
    @JoinColumn(name = "application_module_id")
    private ApplicationModule applicationModule;

    /**
     * 所属企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    /**
     * 审批流层数
     */
    private int level;

    /**
     * 审批流类型
     */
    @Enumerated(value = EnumType.STRING)
    @Column(name = "audit_type")
    private AuditTypeEnum auditTypeEnum;

    /**
     *
     * 完成审批流（[{"organizationId":"1","nodeTypeEnum":"USER","relationId":"2"},{}]）
     *
     */
    @Column(columnDefinition = "longtext")
    private String flow="[]";

    /**
     * 创建人
     */
    @ManyToOne
    @JoinColumn(name = "create_user_id")
    private SystemUser createUser;

    /**
     * 是否为默认
     */
    @Column(columnDefinition = "bit default 0")
    private boolean defaultV;

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public AuditTypeEnum getAuditTypeEnum() {
        return auditTypeEnum;
    }

    public void setAuditTypeEnum(AuditTypeEnum auditTypeEnum) {
        this.auditTypeEnum = auditTypeEnum;
    }

    public String getFlow() {
        return flow;
    }

    public void setFlow(String flow) {
        this.flow = flow;
    }

    public ApplicationModule getApplicationModule() {
        return applicationModule;
    }

    public void setApplicationModule(ApplicationModule applicationModule) {
        this.applicationModule = applicationModule;
    }

    public SystemUser getCreateUser() {
        return createUser;
    }

    public void setCreateUser(SystemUser createUser) {
        this.createUser = createUser;
    }

    public String getFlowName() {
        return flowName;
    }

    public void setFlowName(String flowName) {
        this.flowName = flowName;
    }

    public Boolean getDefaultV() {
        return defaultV;
    }

    public void setDefaultV(Boolean defaultV) {
        this.defaultV = defaultV;
    }

    @Override
    public JSONObject toJSONObject(){
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("flowName", StringConverters.null2String(getFlowName()));
        jsonObject.put("level",StringConverters.null2String(getLevel()));
        jsonObject.put("auditTypeEnum",getAuditTypeEnum()==null?"":getAuditTypeEnum().getName());
        jsonObject.put("applicationName",getApplicationModule()==null?"":getApplicationModule().getApplicationName());
        jsonObject.put("createUser",getCreateUser()==null?"":getCreateUser().getUserName());
        jsonObject.put("enterpriseName",getEnterprise()==null?"":getEnterprise().getEnterpriseName());
        jsonObject.put("defaultV",getDefaultV()?"是":"否");

        return jsonObject;
    }
}
